import {validateToken} from "../util/token";
import {deleteNull} from "../util";

export default class {
    ctx = null;
    next = null;

    getParams() {
        return deleteNull(this.ctx.query)
    }

    getBody() {
        return deleteNull(this.ctx.request.body);
    }

    returnFail(message, code = 501) {
        throw(code, message)
    }

    async getCurrentUser() {
        var token = this.ctx.req.headers.authorization
        if (token) {
            token = token.substr(7, token.length)
        }
        var currentUser = await validateToken(token)
        return currentUser
    }

    constructor(ctx, next) {
        this.ctx = ctx
        this.next = next
    }
}
